package com.study.csc.a05threadPriority2;

/**
 * @author csc
 * @Date 2023/10/18 16:29
 * @PackageName:com.study.csc.a05threadmethod2
 * @ClassName: ThreadDemo
 * @Description: 测试线程的优先级
 * @Version 1.0
 */
public class ThreadDemo {

    public static void main(String[] args) {

    /*

    setPriority(int newPriority)   | 设置线程的优先级
    final int getPriority()      | 获取线程的优先级

        Thread类中的setPriority方法设置线程的优先级取值范围是整数1~10，优先级随着数字的增大而增强
    */

        MyRunnable mr = new MyRunnable();

        Thread t1 = new Thread(mr,"飞机");
        Thread t2 = new Thread(mr,"坦克");

       //设置优先级 1最低  10最高 但是只是代表概率问题. 也就是说 t2的抢到cpu的概率大一些 但是并不绝对.
        //也有可能是优先级最低的线程先执行完成
        t1.setPriority(1);
        t2.setPriority(10);

        t1.start();
        t2.start();

    }

}
